<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\BaseController;
use App\Models\Good;
use App\Models\Slider;
use App\Transformers\GoodTransformer;
use Illuminate\Http\Request;

class IndexController extends BaseController
{
    /**
     * 首页数据
     */
    public function index()
    {
        //轮播图数据
        $sliders = Slider::where('status', 1)->orderBy('seq', 'desc')->get();

        //分类数据
        $categories = cache_category();

        //推荐商品
        $goods = Good::where('is_on',1)
            ->where('is_recommend',1)
            ->get();

        return $this->response->array([
            'sliders' => $sliders,
            'categories' => $categories,
            //'goods' => json_decode($this->response->collection($goods, new GoodTransformer())->morph()->getContent(),true),
            'goods' => $goods
        ]);
    }
}
